import request from "@/utils/request";

export function login(data) {
  return request({
    url: "/user/login",
    method: "post",
    headers: {
      "Content-Type": "application/json",
    },
    data,
  });
}

export function getInfo() {
  return request({
    url: "/user/info",
    method: "get",
  });
}

export function getDetail() {
  return request({
    url: "/user/detailInfo",
    method: "get",
  });
}

// 根据id获取用户详细信息
export function getDetailInfo(id) {
  return request({
    url: `/user/detail/${id}`,
    method: "get",
  });
}

export function logout() {
  return request({
    url: "/user/logout",
    method: "post",
  });
}

export function getUserList() {
  return request({
    url: "/user/list",
    method: "get",
  });
}

export function getGroupList() {
  return request({
    url: "/group/list",
    method: "get",
  });
}

export function createUser(data) {
  return request({
    url: "/user/create",
    method: "post",
    headers: {
      "Content-Type": "application/json",
    },
    data,
  });
}

export function deleteUser(id) {
  return request({
    url: `/user/${id}`,
    method: "delete",
  });
}

export function updateUser(data) {
  return request({
    url: "/user",
    method: "PUT",
    data: {
      id: data.id,
      name: data.name,
      email: data.email,
      telephone: data.telephone,
      groupId: data.groupId,
      avatar: data.avatar,
    },
  });
}

export function getGroupListWithUser() {
  return request({
    url: "/group?includeUsers=true",
    method: "get",
  });
}

export function resetPassword(id) {
  return request({
    url: `/user/resetPassword`,
    method: "put",
  });
}

export function updatePassword(formData) {
  return request({
    url: "/user/updatePassword",
    method: "put",
    data: formData,
  });
}

export function searchUser(data) {
  console.log(data);
  return request({
    url: "/user/search",
    method: "get",
    params: data,
  });
}

export function getUserName(user_id) {
  return request({
    url: "/user/getNameById",
    method: "get",
  });
}
export function getCaptchaImg() {
  return request({
    url: "/user/code",
    method: "get",
  });
}
